import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
/**
 * 配置qiankun
 */
import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";
import type { QiankunProps } from 'vite-plugin-qiankun/dist/helper';
interface MyQiankunProps extends QiankunProps {
  activeRule?: string,
  [key: string]: any
}
let instance: any
const render = (props?: MyQiankunProps) => {
  let renderEl: HTMLElement | null
  console.log(props);
  if (!props || !props?.container) {
    renderEl = document.getElementById("root")
  } else {
    renderEl = props.container
  }
  instance = ReactDOM.createRoot(renderEl!)
  instance.render(
    <React.StrictMode>
      <App />
    </React.StrictMode>,
  )

}
const initQianKun = () => {
  renderWithQiankun({
    mount(props) {
      console.log("%c", "color:green;", " ChildOne mount");
      render(props);
    },
    bootstrap() {
      console.log("%c", "color:green;", " ChildOne bootstrap");
    },
    update() {
      console.log("%c", "color:green;", " ChildOne update");
    },
    unmount(props: any) {
      console.log("unmount", props);
      // instance.unmount();
      // if (instance._container) {
      //   instance._container.innerHTML = "";
      // }
    },
  });
};
if (qiankunWindow.__POWERED_BY_QIANKUN__) {
  console.log("qiankun渲染开始");
  initQianKun();
} else {
  console.log("不是qiankun渲染");
  render();
}

